//
//  JMProductCell.m
//  NewiOSProject
//
//  Created by MAC on 2023/9/14.
//  Copyright © 2023 范智渊. All rights reserved.
//

#import "JMProductCell.h"

@interface JMProductCell()
@property (nonatomic, strong)UIView *contentV;
@property (nonatomic, strong)UIImageView *iconImg;
@property (nonatomic, strong)UILabel *nameLab;
@property (nonatomic, strong)UILabel *priceLab;
@property (nonatomic, strong)UIButton *rightBtn;

@property (nonatomic, strong)UIView *subContV;
@property (nonatomic, strong)UIView *LineV;

@property (nonatomic, strong)UILabel *lab1;
@property (nonatomic, strong)UILabel *lab2;
@property (nonatomic, strong)UILabel *lab3;
@property (nonatomic, strong)UILabel *lab4;
@property (nonatomic, strong)UILabel *valueLab1;
@property (nonatomic, strong)UILabel *valueLab2;
@property (nonatomic, strong)UILabel *valueLab3;
@property (nonatomic, strong)UILabel *valueLab4;
@end
@implementation JMProductCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.backgroundColor = Hex_Str_COLOR(@"#F6F9FE");
        [self setUI];
    }
    return self;
}
-(void)setModel:(JMProductModel *)model{
    _model = model;
    _nameLab.text = model.name;
    [_iconImg sd_setImageWithURL:URLImageWithUrlStr(model.slogan) placeholderImage:nil];
    if (model.productName) {
        _nameLab.text = model.productName;
        _rightBtn.hidden = YES;
    }
    _priceLab.text = [NSString stringWithFormat:@"$%@",model.amount.stringValue.moneyString];
    _valueLab1.text = [NSString stringWithFormat:@"%@Días",model.term.stringValue];
    _valueLab2.text = [NSString stringWithFormat:@"$%@",model.adminAmount.stringValue.moneyString];
    _valueLab3.text = [NSString stringWithFormat:@"$%@",model.repayTotalAmount.stringValue];
    _valueLab4.text = [NSString stringWithFormat:@"%@",model.repaymentPlanTime.dateWithTimeStamp];
    if(model.isFold){
        self.rightBtn.selected = NO;
        self.LineV.hidden = YES;
        [_contentV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@0);
            make.right.equalTo(@(0));
            make.top.equalTo(@0);
            make.height.equalTo(@(ScaleW(105)));
        }];
        [_subContV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@24);
            make.right.equalTo(@(-24));
            make.top.mas_equalTo(self.iconImg.mas_bottom).offset(16);
            make.height.equalTo(@0.1);
        }];
    }else{
        self.LineV.hidden = NO;
        self.rightBtn.selected = YES;
        [_contentV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@0);
            make.right.equalTo(@0);
            make.top.equalTo(@0);
            make.height.equalTo(@(ScaleW(221)));
        }];
        [_subContV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@24);
            make.right.equalTo(@(-24));
            make.top.mas_equalTo(self.priceLab.mas_bottom).offset(16);
            make.height.equalTo(@(ScaleW(100)));
        }];
    }
    
}

-(void)setUI{
    [self.contentView addSubview:self.contentV];
    [self.contentView addSubview:self.LineV];
    @weakify(self)
    [_contentV mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self)
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.equalTo(@(ScaleW(105)));
    }];
    [_subContV mas_remakeConstraints:^(MASConstraintMaker *make) {
        @strongify(self)
        make.left.equalTo(@24);
        make.right.equalTo(@(-24));
        make.top.mas_equalTo(self.iconImg.mas_bottom).offset(16);
        make.height.equalTo(@0.1);
    }];
    
    [_lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self)
        make.left.equalTo(@(8));
        make.height.equalTo(@(ScaleW(25)));
        make.top.equalTo(@0);
    }];
    [_lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self)
        make.left.equalTo(self.lab1);
        make.height.equalTo(@(ScaleW(25)));

        make.top.equalTo(self.lab1.mas_bottom);
    }];
    [_lab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self)
        make.left.equalTo(self.lab1);
        make.height.equalTo(@(ScaleW(25)));

        make.top.equalTo(self.lab2.mas_bottom);
    }];
    [_lab4 mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self)
        make.left.equalTo(self.lab1);
        make.height.equalTo(@(ScaleW(25)));

        make.top.equalTo(self.lab3.mas_bottom);
    }];
    
    [_valueLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self)
        make.right.equalTo(@(-8));
        make.height.equalTo(@(ScaleW(25)));
        make.top.equalTo(@0);
    }];
    [_valueLab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self)
        make.right.equalTo(self.valueLab1);
        make.height.equalTo(@(ScaleW(25)));

        make.top.equalTo(self.valueLab1.mas_bottom);
    }];
    [_valueLab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self)
        make.right.equalTo(self.valueLab1);
        make.height.equalTo(@(ScaleW(25)));

        make.top.equalTo(self.valueLab2.mas_bottom);
    }];
    [_valueLab4 mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self)
        make.right.equalTo(self.valueLab1);
        make.height.equalTo(@(ScaleW(25)));

        make.top.equalTo(self.valueLab3.mas_bottom);
    }];
}


-(UIView *)contentV{
    if(!_contentV){
        _contentV = [UIView new];
        _contentV.backgroundColor = WhiteColor();
        [_contentV addSubview:self.iconImg];
        [_contentV addSubview:self.nameLab];
        [_contentV addSubview:self.rightBtn];
        [_contentV addSubview:self.priceLab];
        [_contentV addSubview:self.subContV];
    }
    return _contentV;
}

-(UIImageView *)iconImg {
    if(!_iconImg){
        _iconImg = [[UIImageView alloc]initWithFrame:(CGRectMake(24, 12, 28, 28))];
//        _iconImg.cornerRadius = 10;
//        _iconImg.backgroundColor = Hex_Str_COLOR(@"#0F1511");
    }
    return _iconImg;
}
-(UILabel *)nameLab {
    if(!_nameLab){
        _nameLab = [JMControl createLabelWithFrame:(CGRectMake(_iconImg.right+14, _iconImg.top, kAppW()/2-30, _iconImg.height)) Font:fontWithWeight(16, UIFontWeightMedium) Text:@"Buen Préstamo" color:Text_COLOR_LEVEL1()];
    }
    return _nameLab;
}
-(UIButton *)rightBtn{
    if(!_rightBtn){
        _rightBtn = [JMControl createButtonWithFrame:(CGRectMake(kAppW()-30-44, 0, 44, 44)) ImageName:@"ICON／you-xiao" Target:self Action:nil font:nil Title:nil];
        [_rightBtn setImage:ImageNamed(@"ICON／XIA-xiao") forState:(UIControlStateSelected)];
        _rightBtn.centerY = 33;
    }
    return _rightBtn;
}
-(UILabel *)priceLab{
    if(!_priceLab){
        _priceLab = [JMControl createLabelWithFrame:(CGRectMake(_iconImg.left, _iconImg.bottom+10, kAppW()-30, 45)) Font:fontWithWeight(32, UIFontWeightMedium) Text:@"" color:Hex_Str_COLOR(@"#3C57F8")];
    }
    return _priceLab;
}
-(UIView *)subContV{
    if(!_subContV){
        _subContV = [UIView new];
        _subContV.cornerRadius = 8;
        _subContV.backgroundColor = Hex_Str_COLOR(@"#F6F9FE");
        [_subContV addSubview:self.lab1];
        [_subContV addSubview:self.lab2];
        [_subContV addSubview:self.lab3];
        [_subContV addSubview:self.lab4];
        [_subContV addSubview:self.valueLab1];
        [_subContV addSubview:self.valueLab2];
        [_subContV addSubview:self.valueLab3];
        [_subContV addSubview:self.valueLab4];
    }
    return _subContV;
}
-(UIView *)LineV{
    if (!_LineV) {
        _LineV = [[UIView alloc]initWithFrame:(CGRectMake(24, _priceLab.bottom+8, kAppW()-48, 1))];
        _LineV.backgroundColor = Hex_Str_COLOR(@"#EBEBED");
    }
    return _LineV;
}
-(UILabel *)lab1{
    if(!_lab1){
        _lab1 = [JMControl createLabelWithFrame:(CGRectZero) Font:Font(12) Text:@"Plazo del préstamo" color:Hex_Str_COLOR(@"#666666") textAlignment:0 numberOfLine:0];//贷款期限
    }
    return _lab1;
}
-(UILabel *)lab2{
    if(!_lab2){
        _lab2 = [JMControl createLabelWithFrame:(CGRectZero) Font:Font(12) Text:@"Tarifas por servicio" color:Hex_Str_COLOR(@"#666666") textAlignment:0 numberOfLine:0];//服务费

    }
    return _lab2;
}
-(UILabel *)lab3{
    if(!_lab3){
        _lab3 = [JMControl createLabelWithFrame:(CGRectZero) Font:Font(12) Text:@"Monto reembolsable" color:Hex_Str_COLOR(@"#666666") textAlignment:0 numberOfLine:0];//可贷金额
    }
    return _lab3;
}
-(UILabel *)lab4{
    if(!_lab4){
        _lab4 = [JMControl createLabelWithFrame:(CGRectZero) Font:Font(12) Text:@"Gastos de servicio" color:Hex_Str_COLOR(@"#666666") textAlignment:0 numberOfLine:0];//时间
    }
    return _lab4;
}
-(UILabel *)valueLab1{
    if(!_valueLab1){
        _valueLab1 = [JMControl createLabelWithFrame:(CGRectZero) Font:Font(12) Text:@"" color:Hex_Str_COLOR(@"#666666") textAlignment:2 numberOfLine:0];

    }
    return _valueLab1;
}

-(UILabel *)valueLab2{
    if(!_valueLab2){
        _valueLab2 = [JMControl createLabelWithFrame:(CGRectZero) Font:Font(12) Text:@"" color:Hex_Str_COLOR(@"#666666") textAlignment:2 numberOfLine:0];

    }
    return _valueLab2;
}

-(UILabel *)valueLab3{
    if(!_valueLab3){
        _valueLab3 = [JMControl createLabelWithFrame:(CGRectZero) Font:Font(12) Text:@"" color:Hex_Str_COLOR(@"#666666") textAlignment:2 numberOfLine:0];

    }
    return _valueLab3;
}

-(UILabel *)valueLab4{
    if(!_valueLab4){
        _valueLab4 = [JMControl createLabelWithFrame:(CGRectZero) Font:Font(12) Text:@"" color:Hex_Str_COLOR(@"#666666") textAlignment:2 numberOfLine:0];

    }
    return _valueLab4;
}

//Plazo del préstamo
//Tarifas por servicio
//Monto reembolsable
//Gastos de servicio
@end
